package action;

import infrastructure.IDossier;
import infrastructure.IDossierInfraction;
import mappers.DossierInfractionMapper;

import org.apache.struts2.ServletActionContext;

public class InfractionDossierActions extends VisualiserInfractionAction {
	private static final long serialVersionUID = 1L;
	// dossier selection grace au id
	private IDossierInfraction dossierInfraction;
	private IDossier dossierSelectionne;
	private DossierInfractionMapper dossierInfractionDAO;

	public void setDossierInfractionDAO(DossierInfractionMapper dossierInfractionDAO) {
		this.dossierInfractionDAO = dossierInfractionDAO;
	}
	public IDossier getDossierSelectionne() {
		return dossierSelectionne;
	}

	public IDossierInfraction getDossierInfraction() {
		return dossierInfraction;
	}

	public void setDossierInfraction(IDossierInfraction dossierInfraction) {
		this.dossierInfraction = dossierInfraction;
	}

	public String visualiserInfraction() {
		Object sessionDossier = ServletActionContext.getRequest().getSession()
				.getAttribute("DossierCourant");
		if (sessionDossier != null){
			if (sessionDossier instanceof IDossier) {
				dossierSelectionne = (IDossier) sessionDossier;
			}
			else
			{
				return ERROR;
			}
		}		
		return visualiserInfractions();
	}

	public String addDossierInfraction() {
		dossierInfractionDAO.insert(dossierInfraction);
		return SUCCESS;
	}
}
